package com.example.yunifang.fragment;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.Toast;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.tencent.qq.QQ;

import com.example.yunifang.DengluActivity;
import com.example.yunifang.MainActivity;
import com.example.yunifang.R;
import com.example.yunifang.SheZhiActivity;
import com.example.yunifang.adapter.Fragment4Adapter;
import com.example.yunifang.bean.Fragment4Bean;
import com.example.yunifang.myview.MyImageView;
import com.nostra13.universalimageloader.core.ImageLoader;

public class Fragment4 extends Fragment implements OnClickListener {
	private ListView fragment4_lv;
	private View view;
	private ArrayList<Fragment4Bean> data = new ArrayList<Fragment4Bean>();
	private RadioButton fragment4_denglu;
	private boolean flag=true;
	private MyImageView img_back_qqtitle;
	private ImageView fragment4_shezhi;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		view = View.inflate(getActivity(), R.layout.fragment4, null);
		String name=getActivity().getIntent().getStringExtra("userImg");
		fragment4_lv = (ListView) view.findViewById(R.id.fragment4_lv);
		fragment4_denglu = (RadioButton) view
				.findViewById(R.id.fragment4_denglu);
		img_back_qqtitle=(MyImageView)view.findViewById(R.id.img_back_qqtitle);
		if(name!=null){
			ImageLoader.getInstance().displayImage(name, img_back_qqtitle);
		}
		fragment4_denglu.setOnClickListener(this);
		initData();
		fragment4_lv.setAdapter(new Fragment4Adapter(getActivity(), data));
		fragment4_shezhi=(ImageView)view.findViewById(R.id.fragment4_shezhi);
		fragment4_shezhi.setOnClickListener(this);
		return view;
	}

	private void initData() {
		// TODO Auto-generated method stub
		Fragment4Bean bean0=new Fragment4Bean(R.drawable.my_order_icon, "我的订单");
		Fragment4Bean bean1 = new Fragment4Bean(R.drawable.my_vip_icon, "会员福利");
		Fragment4Bean bean2 = new Fragment4Bean(R.drawable.my_coupon_icon,
				"邀请有礼");
		Fragment4Bean bean3 = new Fragment4Bean(R.drawable.my_lottery_icon,
				"我的现金卷");
		Fragment4Bean bean4 = new Fragment4Bean(
				R.drawable.personal_center_contact_service_icon, "联系客服");
		Fragment4Bean bean5 = new Fragment4Bean(R.drawable.my_collection_icon,
				"我的抽奖单");
		data.clear();
		data.add(bean0);
		data.add(bean1);
		data.add(bean2);
		data.add(bean3);
		data.add(bean4);
		data.add(bean5);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.fragment4_denglu:
			denglu();
			break;
		case R.id.fragment4_shezhi:
			Intent intent=new Intent(getActivity(),SheZhiActivity.class);
			startActivity(intent);
			getActivity().overridePendingTransition(R.anim.outactivity, R.anim.inactivity);
			break;
		default:
			break;
		}
	}

	private void denglu() {
		// TODO Auto-generated method stub
		if(flag==true){
			Intent intent=new Intent(getActivity(),DengluActivity.class);
			startActivity(intent);
			getActivity().overridePendingTransition(R.anim.outactivity, R.anim.inactivity);
			flag=false;
		}else{
			Toast.makeText(getActivity(), "签到", 0).show();
			fragment4_denglu.setText("签到");
			flag=true;
		}
	}

}
